/*
 * Copyright (c) 2018.
 * This file was written by Fancyears·Milos·Malvis @connor. Any question/bug you can't post to 1243093366@qq.com.
 * ALL RIGHTS RESERVED.
 */
package org.fancyears.frame;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.MouseInfo;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;

import org.fancyears.commom.InitializationWithSkin;
import org.jb2011.lnf.beautyeye.ch3_button.BEButtonUI;
import org.jb2011.lnf.beautyeye.ch6_textcoms.BETextFieldUI;
import org.jb2011.swing9patch.toast.Toast;


/**
 * @author: Fancyears·Milos·Malvis
 * @CreateDate: 2018年12月4日 上午9:30:51
 * @Description:
 */

public class YFrame extends  InitializationWithSkin  implements ActionListener {


	public YFrame() {
//		setCustomSkin(true);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		JButton jb=(JButton)e.getSource();
		String text=jb.getText();
		Point p=MouseInfo.getPointerInfo().getLocation(); 
//		JOptionPane jOptionPane=new JOptionPane("Hello", JOptionPane.WARNING_MESSAGE);
		Toast toast=new Toast(500, "Toast"+text, p);
		toast.showItNow();
	}

	@Override
	public boolean init() throws Exception {
		jf = new JFrame("Hello");
		jf.setSize(200, 300);
		return true;
	}

	@Override
	public void createContents() throws Exception {
		JButton button = new JButton("点击生效");
		button.setPreferredSize(new Dimension(100, 100));
		button.setUI(new BEButtonUI().setNormalColor(BEButtonUI.NormalColor.normal));

		JButton button2 = new JButton("点击生效");
		button2.setPreferredSize(new Dimension(100, 100));
		button2.setUI(new BEButtonUI().setNormalColor(BEButtonUI.NormalColor.green));

		JButton button3 = new JButton("点击生效");
		button3.setPreferredSize(new Dimension(100, 100));
		button3.setUI(new BEButtonUI().setNormalColor(BEButtonUI.NormalColor.lightBlue));

		JButton button4 = new JButton("点击生效");
		button4.setPreferredSize(new Dimension(100, 100));
		button4.setUI(new BEButtonUI().setNormalColor(BEButtonUI.NormalColor.blue));

		JButton button5 = new JButton("点击生效");
		button5.setPreferredSize(new Dimension(100, 100));
		button5.setUI(new BEButtonUI().setNormalColor(BEButtonUI.NormalColor.red));

		JPanel panel = new JPanel();
		panel.setLayout(new BorderLayout());

		JLabel jLabel = new JLabel("Test");
		jLabel.setPreferredSize(new Dimension(36, 36));

		JTextField field = new JTextField(24);
		field.setSize(new Dimension(40, 36));
		field.setUI(new BETextFieldUI());
		panel.add(jLabel, BorderLayout.WEST);
		panel.add(field, BorderLayout.CENTER);

		JTable jTable = new JTable();
		DefaultTableModel model = new DefaultTableModel();
		jTable.setModel(model);
		jTable.setPreferredSize(new Dimension(100, 100));
		jTable.setVisible(true);
		for (int i = 0; i < 10; i++) {
//			TableColumn column = new TableColumn();
//			column.setHeaderValue("Title" + i);
			model.addColumn("Title" + i/*column*/);
		}
		for (int j = 0; j < 5; j++) {
			Vector<String> v = new Vector<>();
			for (int i = 0; i < 10; i++) {
				v.add("Data" + i);
			}
			model.addRow(v);
		}
//		jTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
		
		JScrollPane scrollPane=new JScrollPane();
		scrollPane.setVisible(true);
		scrollPane.add(jTable);
		scrollPane.setViewportView(jTable);
		
		GridBagLayout gbl = new GridBagLayout();
		jf.setLayout(gbl);
		jf.add(button);
		jf.add(button2);
		jf.add(button3);
		jf.add(button4);
		jf.add(button5);
		jf.add(panel);
		jf.add(scrollPane);

		GridBagConstraints gbs = new GridBagConstraints();
		gbs.fill = GridBagConstraints.BOTH;
		gbs.gridwidth = 1;
		gbs.gridheight = 1;
		gbs.insets = new Insets(1, 1, 1, 1);
		gbs.weightx = 1;
		gbs.weighty = 1;
		gbs.gridx = 0;
		gbs.gridy = 0;
		gbl.setConstraints(button, gbs);

		gbs.insets = new Insets(1, 1, 1, 1);
		gbs.weightx = 1;
		gbs.weighty = 1;
		gbs.gridx = 0;
		gbs.gridy = 1;
		gbl.setConstraints(button2, gbs);

		gbs.insets = new Insets(1, 1, 1, 1);
		gbs.weightx = 1;
		gbs.weighty = 1;
		gbs.gridx = 1;
		gbs.gridy = 0;
		gbl.setConstraints(button3, gbs);

		gbs.insets = new Insets(1, 1, 1, 1);
		gbs.weightx = 1;
		gbs.weighty = 1;
		gbs.gridx = 1;
		gbs.gridy = 1;
		gbl.setConstraints(button4, gbs);

		gbs.insets = new Insets(1, 1, 1, 1);
		gbs.weightx = 2;
		gbs.weighty = 2;
		gbs.gridx = 2;
		gbs.gridy = 0;
		gbl.setConstraints(button5, gbs);

		gbs.insets = new Insets(1, 1, 1, 1);
		gbs.weightx = 1;
		gbs.weighty = 1;
		gbs.gridx = 2;
		gbs.gridy = 1;
		gbl.setConstraints(panel, gbs);

		gbs.insets = new Insets(1, 1, 1, 1);
		gbs.weightx = 1;
		gbs.weighty = 1;
		gbs.gridx = 2;
		gbs.gridy = 2;
		gbl.setConstraints(scrollPane, gbs);

		button.addActionListener(this);
		button2.addActionListener(this);
		button3.addActionListener(this);
		button4.addActionListener(this);
		button5.addActionListener(this);

	}

//	@Override
//	public void addSkin() throws Exception {
//	}
	
}
